//
//  UIBarButtonItem+Extensions.swift
//  WinsonWeibo
//
//  Created by Administrator on 2017/4/14.
//  Copyright © 2017年 Winson. All rights reserved.
//

import UIKit

extension UIBarButtonItem {

    /// 便利构造导航栏按钮
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize default = 16
    ///   - target: target
    ///   - action: action 
    convenience init(title: String, fontSize: CGFloat = 16, target: Any?, action: Selector, isBack: Bool = false) {
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)

        if isBack {
            let imageName = "navigationbar_back_withtext"
            let hightlighted_imageNmae = "navigationbar_back_withtext_highlighted"

            btn.setImage(UIImage(named: imageName), for: UIControlState.normal)
            btn.setImage(UIImage(named: hightlighted_imageNmae), for: UIControlState.highlighted)
            btn.sizeToFit()

        }

        btn.addTarget(target, action: action, for: UIControlEvents.touchUpInside)

        // 便利构造函数要调用自己init（） 方法
        self.init(customView: btn)
    }
}
